/**
 * @param {number} buttonHeight 底部按钮高度
 * @param {number} otherHeight 其他高度
 * @description 设置滚动区域宽度
 */
export const setScrollHeight = (otherHeight = 0) => {
  let navBarH = 0;

  // app时添加导航栏
  //  #ifdef APP-PLUS
  navBarH = BasicConfig.NAVBAR_HEIGHT;
  //  #endif

  // pc端添加导航栏高度
  if (verifyPc()) {
    navBarH = BasicConfig.NAVBAR_HEIGHT;
  }
  // 获取手机系统信息
  const info = uni.getSystemInfoSync();
  // 设置状态栏高度
  const statusBarHeight = info.statusBarHeight;

  const height = navBarH + otherHeight + statusBarHeight;

  return {
    height: `calc(100vh - ${height}px)`
  };
};

/**
 * @param {any[]} tableData 表格数据
 * @param {String} 过滤的字段多个以逗号分隔
 * @description 表格类型1数据过滤
 */

export const filterDataGrid = (tableData: any[], prop: string, value) => {
  const data = JSON.parse(JSON.stringify(tableData));

  const newData = data.filter(item => {
    const v = prop.split(",");
    let flag;
    for (let sonProp of v) {
      const n = item[sonProp] + "";
      if (n.includes(value)) {
        flag = true;
      }
    }
    return flag;
  });
  return newData;
};

/**
 * @param {String} value 提交的内容
 * @description 表格类型2 数据过滤
 */

export const filterDataGrid2 = (tableData: any[], prop: string, value) => {
  const data = JSON.parse(JSON.stringify(tableData));

  const newData = data.filter(item => {
    item.value = item.value.filter(son => {
      const v = prop.split(",");
      let flag;
      for (let sonProp of v) {
        const n = son[sonProp] + "";
        if (n.includes(value)) {
          flag = true;
        }
      }
      return flag;
    });
    return item.value.length;
  });
  return newData;
};
